<template>
	<view class="container">
		<view class="head-box">
			<view style="width: calc((100% / 5) * 2);" class="head-tiem">
				时间
			</view>
			<view style="width: calc(100% / 5);" class="head-type">
				提现金额
			</view>
			<view style="width: calc(100% / 5);" class="head-type">
				到账金额
			</view>
			<view style="width: calc(100% / 5); text-align: center;" class="head-statue">
				状态
			</view>
		</view>
		<mescroll-body style="background-color: #fff;" ref="mescrollRef" :sticky="true" @init="mescrollInit"
			:down="{ use: false }" :up="upOption" @up="upCallback">
			<view class="log-list">
				<view v-for="(item, index) in list.data" :key="index" class="log-item">
					<view style="width: calc((100% / 5) * 2);" class="rec-time">
						<text>{{ item.create_time }}</text>
					</view>
					<view style="width: calc(100% / 5);" class="item-left">
						<view class="rec-status">
							<text>{{ item.money }}</text>
						</view>
					</view>
					<view style="width: calc(100% / 5);" class="item-left">
						<view class="rec-status">
							<text>{{ item.left_money }}</text>
						</view>
					</view>
					<view style="width: calc(100% / 5); text-align: center;" class="item-right">
						<text>{{ setStatus(item.status) }}</text>
					</view>
				</view>
			</view>
		</mescroll-body>
	</view>
</template>

<script>
	import MescrollBody from '@/components/mescroll-uni/mescroll-body.vue'
	import MescrollMixin from '@/components/mescroll-uni/mescroll-mixins'
	import * as withdrawApi from '@/api/withdrawCash'
	import {
		getEmptyPaginateObj,
		getMoreListData
	} from '@/core/app'

	const pageSize = 15

	export default {
		components: {
			MescrollBody
		},
		mixins: [MescrollMixin],
		data() {
			return {
				// 充值记录
				list: getEmptyPaginateObj(),
				// 上拉加载配置
				upOption: {
					// 首次自动执行
					auto: true,
					// 每页数据的数量; 默认10
					page: {
						size: pageSize
					},
					// 数量要大于12条才显示无更多数据
					noMoreSize: 12,
					// 空布局
					empty: {
						tip: '亲，暂无相关数据'
					}
				}
			}
		},

		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad(options) {},

		methods: {
			setStatus(num) {
				let statusValue = '';
				switch (num) {
					case 1:
						return '提现中';
						break;
					case 2:
						return '提现成功';
						break;
					case 3:
						return '提现失败';
						break;
					case 4:
						return '转账中';
						break;
					default:
						break;
				}
			},

			leftBack() {
				uni.navigateBack(1);
			},
			/**
			 * 上拉加载的回调 (页面初始化时也会执行一次)
			 * 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10
			 * @param {Object} page
			 */
			upCallback(page) {
				const app = this
				// 设置列表数据
				app.getLogList(page.num)
					.then(list => {
						const curPageLen = list.data.length
						const totalSize = list.data.total
						app.mescroll.endBySize(curPageLen, totalSize)
					})
					.catch(() => app.mescroll.endErr())
			},

			// 获取积分明细列表	
			getLogList(pageNo = 1) {
				const app = this
				return new Promise((resolve, reject) => {
					withdrawApi.withdrawLog({
							page: pageNo
						})
						.then(result => {
							// 合并新数据
							const newList = result.data.list
							app.list.data = getMoreListData(newList, app.list, pageNo)
							resolve(newList)
						})
				})
			}

		}
	}
</script>

<style lang="scss" scoped>
	page,
	.container {
		background: #f6f6f6;

		.head-box {
			display: flex;
			justify-content: space-around;
			padding: 16px;
			margin-bottom: 10px;
			background-color: #fff;
		}
	}

	.log-list {
		text-align: left;
	}

	.log-item {
		padding: 16px;
		display: flex;
		justify-content: space-around;
		font-size: 20rpx;
		border-bottom: 1rpx solid rgb(238, 238, 238);
	}

	.rec-status {
		color: #333;

		.rec-time {
			color: rgb(160, 160, 160);
			font-size: 26rpx;
		}
	}
</style>
